//
//  ViewController.m
//  TQY
//
//  Created by 甘世清 on 2024/7/5.
//

#import "ViewController.h"

#import "HomeLetterViewController.h"
#import "HomeMeViewController.h"
#import "WritingBaseViewController.h"
#import "MateViewController.h"
#import "BasePeopleViewController.h"
#import "TQYSocketManager.h"
#import "TicketPopView.h"
#import "AuthenticationViewController.h"

#import "IMListViewController.h"
@interface ViewController ()
@property (nonatomic , strong) MateViewController * matteVC;
@property (nonatomic , strong) WritingBaseViewController * writingVC;
@property (nonatomic , strong) IMListViewController * messageVC;
@property (nonatomic , strong) HomeMeViewController * meVC;
@property (nonatomic , strong) BasePeopleViewController * peopleVC;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self SQ_footer];
    self.view.backgroundColor = UIColor.whiteColor;
    self.navigationController.navigationBarHidden = YES;
    [self SQ_uiViewForSelf];
    [self SQ_Header];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(SQ_reloadMessageCount) name:@"IMMessageModel" object:nil];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self SQ_reloadMessageCount];
}

-(void)SQ_uiViewForSelf{
    [TQYSocketManager SQ_SocketManager];
     self.tabBar.backgroundColor = UIColor.whiteColor;
    [self setTabBarFrame:CGRectMake(0, SCREEN_HEIGHT-50-FootHeight, SCREEN_WIDETH, 50)
        contentViewFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT-FootHeight-50)];
    self.tabContentView.delegate = self;
 
    self.tabContentView.loadViewOfChildContollerWhileAppear = YES;
    self.viewControllers = [NSMutableArray arrayWithObjects:self.matteVC,self.peopleVC, self.messageVC,self.writingVC,self.meVC,nil];
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = SQColorF5F5F5;
    [self.tabBar addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.tabBar);
            make.height.mas_equalTo(1);
    }];
    [self.tabBar setItemContentHorizontalCenterAndMarginTop:10 spacing:0];
    
}
-(void)SQ_reloadMessageCount{
    self.messageVC.yp_tabItem.badge = [[TQYFMDBManager SQ_getMessageCount] integerValue];
}
- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [HttpTool post:@"user/info" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [UserModel SQ_updateLocal:httpModel];
        if ([UserModel share].gender == 2) {
            if ([UserModel share].realStatus == -1|| [UserModel share].realStatus == 1) {
                AuthenticationViewController * vc = [[AuthenticationViewController alloc]init];
                vc.isPush = YES;
                [self.navigationController pushViewController:vc animated:NO];
            }
        }else{
            [TicketPopView SQ_showTickView:self.view];
        }
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
      
    }];
}

-(void)SQ_footer{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"app_recommended" forKey:@"key"];
    [HttpTool post:@"config/details" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        NSString * value = [NSString stringWithFormat:@"%@",[httpModel.data objectForKey:@"value"]];
        [Manager SQ_SetObject:value FormKey:@"app_recommended"];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
    }];
}
/**
 *  是否能切换到指定index
 */
//- (BOOL)tabContentView:(YPTabContentView *)tabConentView shouldSelectTabAtIndex:(NSUInteger)index{
//    if (index==1) {
//        return YES;
//    }
//    UserModel * model = [UserModel share];
//    if ([model.portrait isNotEmpty]&&[model.name isNotEmpty]) {
//        return YES;
//    }
//    SetInfoViewController * vc = [[SetInfoViewController alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
//    [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"该功能需要先完善个人信息方可使用!")];
//    return NO;
//}
- (BasePeopleViewController *)peopleVC{
    if (!_peopleVC) {
        _peopleVC = [[BasePeopleViewController alloc]init];
        _peopleVC.yp_tabItemImage = SQGetImage(@"用户 灰");
        _peopleVC.yp_tabItemSelectedImage = SQGetImage(@"用户 亮");
    }
    return _peopleVC;
}
- (MateViewController *)matteVC{
    if (!_matteVC) {
        _matteVC = [[MateViewController alloc]init];
        _matteVC.yp_tabItemImage = SQGetImage(@"热门 灰");
        _matteVC.yp_tabItemSelectedImage = SQGetImage(@"热门 亮");
    }
    return _matteVC;
}

- (WritingBaseViewController *)writingVC{
    if (!_writingVC) {
        _writingVC = [[WritingBaseViewController alloc]init];
        _writingVC.yp_tabItemImage = SQGetImage(@"发现 灰");
        _writingVC.yp_tabItemSelectedImage = SQGetImage(@"发现 亮");
    }
    return _writingVC;
}


 
- (IMListViewController *)messageVC{
    if (!_messageVC) {
        _messageVC = [[IMListViewController alloc]init];
        _messageVC.yp_tabItemImage = SQGetImage(@"通知 灰");
        _messageVC.yp_tabItemSelectedImage = SQGetImage(@"通知 亮");
        _messageVC.yp_tabItem.badgeStyle =YPTabItemBadgeStyleNumber;
    }
    return _messageVC;
}
- (HomeMeViewController *)meVC{
    if (!_meVC) {
        _meVC = [[HomeMeViewController alloc]init];
        _meVC.yp_tabItemImage = SQGetImage(@"个人 灰");
        _meVC.yp_tabItemSelectedImage = SQGetImage(@"个人 亮");
    }
    return _meVC;
}


@end
